<style>
    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }

    .el-input__inner {
        height: 30px !important;
    }

    .layui-form .el-cascader {
        line-height: 30px;
        ;
    }
</style>
<div class="rightcontent rc-bg-grey">
    <div class="rc-pagepadding ">
        <div class=" rc-pannel layui-form">
            <div class=" rc-pannel-header rc-pagepadding rc-bold">
                <i class="iconfont goback rc-pointer">&#xe62b;</i> 编辑导航
            </div>
            <div class="rc-pannel-body  rc-pagepadding">

                <div class="layui-form-item">
                    <label class="layui-form-label">导航分类</label>
                    <div class="layui-input-block">
                        <select name="cid">
                            <?php
                            foreach ($cates as $cate) {
                            ?>
                                <option value="<?php echo $cate['id'] ?>" <?php echo $menuinfo['cid'] == $cate['id'] ? 'selected' : '' ?>><?php echo $cate['title']; ?></option>
                            <?php
                            }
                            ?>
                        </select>

                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">父级导航</label>
                    <div class="layui-input-block">
                        <input type="text" name="pid" id="pid" autocomplete="off" value="0" lay-verify="required" class="layui-input" title="分类名称" />

                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">导航名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" autocomplete="off" value="<?php echo $menuinfo['title']; ?>" lay-verify="required" class="layui-input" title="分类名称" />

                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">链接地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="url" autocomplete="off" value="<?php echo $menuinfo['url']; ?>" lay-verify="required" class="layui-input" title="分类名称" />

                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">导航图标</label>
                    <div class="layui-input-block">
                        <?php echo element('singleimage', name: 'iconpic', value: $menuinfo['iconpic']) ?>

                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">打开方式</label>
                    <div class="layui-input-block">

                        <select name="target">
                            <option value="_blank" <?php echo $menuinfo['target'] == '_blank' ? 'selected' : ''; ?>>新窗口</option>
                            <option value="_self" <?php echo $menuinfo['target'] == '_self' ? 'selected' : ''; ?>>本窗口</option>
                        </select>

                    </div>
                </div>


                <div class="layui-form-item rc-margin-bottom0">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="submit">提交</button>
                        <button type="reset" class="layui-btn layui-btn-sm">重置</button>
                    </div>
                </div>

            </div>



        </div>

    </div>
</div>
<script src="/static/admin/lib/layui/modules/cascader/cascader.js"></script>
<script>
    layui.use(function() {

        var form = layui.form;
        var layCascader = layui.layCascader;
        var el_cascaderdata = '<?php echo $menus ?>';
        var el_cascaderdata_obj = eval("(" + el_cascaderdata + ")");

        var el_cascader_ = layCascader({
            elem: '#pid',
            filterable: true,
            options: el_cascaderdata_obj,
            props: {
                value: 'id',
                label: 'title',
                checkStrictly: true,
            }
        });
        el_cascader_.setValue(<?php echo $menuinfo['pid'] ?>);

        form.on('submit(submit)', function(data) {
            delete data.field['iconpic_file'];
            $.ajax({
                url: '/admin/HomeMenu/editemenu?id=<?php echo request()->get('id') ?>', //请求路径
                type: "POST", //请求方式
                data: data.field, // 默认写法
                success: function(data) {
                    if (data.code == 0) {
                        toastr_success("编辑成功", function() {
                            window.location.href = '/admin/HomeMenu/menus';
                        });
                    } else {
                        toastr_error(data.message);
                    }
                },
                error: function() {

                },

            });
        });



    });
</script>